package com.learn.gc;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenxin
 * @time 2017-04-19-11:14
 */
public class CrossReference {
    // jdk1.7  -Xmx500M -Xms500M -Xmn200M -XX:+UseConcMarkSweepGC
    // -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=90
    private static int unit = 20 * 1024;

    public static void main(String[] args) throws Exception{
        Thread.sleep(5000);
        System.out.println("allocate start************");
        allocate();


        Thread.sleep(1000);
        System.out.println("allocate end************");
        Thread.sleep(30000);
    }

    private static void allocate() throws Exception{
        List<BigObject> list = new MyArrayList<>();
        int size = 1024 * 1024 * 400; // 400M
        int len = size / unit;

        for( int i = 0; i < len; i++){

            BigObject bigObject = new BigObject();
            list.add(bigObject);
            Thread.sleep(5);
        }
    }

    private static class BigObject{
        private byte[] foo;

        BigObject(){
            foo = new byte[unit];
        }
    }

    private static class MyArrayList<E> extends ArrayList<E>{
        public MyArrayList() {
            super();
        }

        public MyArrayList(int initialCapacity){
            super(initialCapacity);
        }
    }


}
